public class MyQueue {
    static class ListNode{
        public int val;
        public ListNode prev;
        public ListNode next;

        public ListNode(int val) {
            this.val = val;
        }
    }
    public ListNode head;
    public ListNode last;
    public int usedSize = 0;

    public void offer(int val){
        ListNode node = new ListNode(val);
        if(isEmpty()){
            head = last = node;
        }
        last.next = node;
        node.prev = last;
        last = node;
        usedSize++;
    }

    public int pull(){
        if(isEmpty()){
            throw new PopIndexException();
        }else{
            int val = head.val;
            head = head.next;
            if(head != null){
                head.prev = null;
            }
            usedSize--;
            return val;
        }

    }

    private boolean isEmpty(){
        return usedSize == 0;
    }

    public int peek(){
        return head.val;
    }
}
